
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Display;

public class Search extends Form implements CommandListener {

    private TextField tf = new TextField("Nhập nội dung tìm kiếm: ", "", 99, TextField.ANY);
    private Command search = new Command("Search Song", Command.ITEM, 0);
    private Command search1 = new Command("Search Singer", Command.ITEM, 0);
    private Command back = new Command("Back", Command.BACK, 0);

    public Search() {
        super("Search");
        this.append(tf);
        this.addCommand(search);
        this.addCommand(search1);
        this.addCommand(back);
        this.setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {
        String sKeywork = tf.getString().replace(' ', '+');
        if (c == search) {
            f_readsong frm1 = new f_readsong(0);
            frm1.load("search.php?name=" + sKeywork);
            f_readplaylist frm2 = new f_readplaylist(0);
            frm2.load("search.php?type=playlist&name=" + sKeywork);
            frm1.title = frm2.title = "Results for '"+tf.getString()+"'";
            if (AppManager.isSearching) {
                AppManager.backSearch();
            } else {
                AppManager.isSearching = true;
            }
            AppManager.open(frm1,frm2,false);
        }
        if (c == search1) {
            f_readsong frm1 = new f_readsong(0);
            frm1.load("search.php?singer=" + sKeywork);
            f_readplaylist frm2 = new f_readplaylist(0);
            frm2.load("search.php?type=playlist&singer=" + sKeywork);
            frm1.title = frm2.title = "Results for '"+tf.getString()+"'";
            if (AppManager.isSearching) {
                AppManager.backSearch();
            } else {
                AppManager.isSearching = true;
            }
            AppManager.open(frm1,frm2,false);
        }
        if (c == back) {
            AppManager.back();
            AppManager.isSearching = false;
        }

    }
}
